package sctu.edu.java.year2016.team01.xuhanmei.day20160522.practice2;

/**
 * Created by Administrator on 2016/5/24.
 */
public class Juzhen1 {
    public static void main(String[] args) {
    int arr1[][]=new int[][]{{1,2,3},{4,5,6},{7,8,9}};//这是一个方阵，如果不是方阵，方法也一样吗?
    System.out.println("这个矩阵的原型是这样：");
    PrintArray(arr1);
    int arr2[][]=new int[arr1.length][arr1.length];
    for(int i=0;i<arr1.length;i++){
        for(int j=0;j<arr1[i].length;j++){
            arr2[j][i]=arr1[i][j];
        }
    }
    System.out.println("转置后的矩阵是：");
    PrintArray(arr2);
}

    private static void PrintArray(int[][] arr1) {
        for(int a=0;a<arr1.length;a++){
            for(int b=0;b<arr1.length;b++){
                System.out.print(arr1[a][b]+"\t");
            }
            System.out.println();
        }
    }
}
